package com.bd1904.common;

import org.apache.commons.lang3.time.FastDateFormat;

import java.text.ParseException;
import java.util.Date;

public class DateUtil {


    private static FastDateFormat df1 = FastDateFormat.getInstance("yyyyMMddHHmmss");
    private static FastDateFormat df2 = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");

    //现在需要将yyyyMMddHHmmss ==》yyyy-MM-dd HH:mm:ss
    public static String formatTime(String srcTime) {
        try {
            Date srcDate = df1.parse(srcTime);
            return df2.format(srcDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String formatDate(Date date) {
        return df1.format(date);
    }

    public static Date parse2Date(String time) {
        try {
            return df2.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
